package com.codefox.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.codefox.entity.TbDisease;
import com.codefox.service.TbDiseaseService;

/**
 * 疾病类的控制层代码
 *
 * @author xiaobiye
 * @date 2018年9月28日16:37:22
 */
@Controller
@RequestMapping(value = { "front", "back" })
public class TbDiseaseController {
	@Autowired
	TbDiseaseService diseaseService;

	/**
	 * 返回所有疾病的json
	 * 
	 * @return json字符串
	 */
	@ResponseBody
	@RequestMapping(value="/diseaseList",produces = "application/json;charset=UTF-8")
	public String list() {
		/* System.out.println("disease-->list"); */
		List<TbDisease> list = diseaseService.listDisease();
		String json = JSONObject.toJSONString(list);
		return json;
	}

	@ResponseBody
	@RequestMapping("/diseaseDelete")
	public String delete(@RequestParam("id")Integer id) {
		if(diseaseService.delete(id)>0) {
			return "Y";
		}
		return "N";
	}

	@ResponseBody
	@RequestMapping("/diseaseEdit")
	public String update(TbDisease disease) {
		if(diseaseService.update(disease)>0) {
			return "Y";
		}
		return "N";
	}

	@ResponseBody
	@RequestMapping("/diseaseAdd")
	public String add(TbDisease disease) {
		if(diseaseService.add(disease)>0) {
			return "Y";
		}
		return "N";
	}
}
